//上传图片
//var filer="";
function verify(val) {
	var file = document.getElementById("file") ? document.getElementById("file").files[0]:document.getElementById("file2").files[0];
	var imgtype = file.type
//	console.log("图片格式:"+imgtype)
	if(imgtype == "image/jpeg" || imgtype == "image/png") {
		var reader = new FileReader();
		reader.onload= function (e) {
			document.getElementById('imgdome') ? document.getElementById('imgdome').setAttribute('src', e.target.result):document.getElementById('imgdome2').setAttribute('src', e.target.result)
//			filer=e.target.result;
//			main.response.photo=e.target.result
			yashuo(e.target.result)
        };
        reader.readAsDataURL(file);
     }else {
		log_message("请上传jpg或PNG格式的图片")
	}
}
function yashuo(filer){
	lrz(filer,{
		width:512
	})
	.then(function(rst){
		main.response.photo=rst.base64.match(/base64,(\S*)/)[1]
	})
};
var main = new Vue({
	el: '#main',
	data: {
		response:{
			"xm": "",
			"xb": "",//（0：女；1：男）
			"nl": "",
			"zjhm": "",
			"photo": "",
			"mobilePhone": "",
			"whcd": "", 
			"csrq": "", 
			"lxr": "", 
			"lxrGx": "",
			"lxrDz": "",
			"lxrLxdh": "",
			"mz": "01",
			"hyzk": "",
			"csd": "",
			"address": "",
			"hkdz": "",
			"aboxx": "",
			"rhxx": "",
			"zy": "",
			"sbkg": "",
			"gj": "156",

		},
	},
	computed: {
		reversedminzhu:function(){
	    		var zhi=''
		    	var this_=this
		    minzu.forEach(function(value,i){
		     	if(value.value==this_.response.mz){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	    reversedguojia:function(){
	    		var zhi=''
		    	var this_=this
		    guojia.forEach(function(value,i){
		     	if(value.value==this_.response.gj){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	    },
	    reversedhunyin:function(){
	    		var zhi=''
		    	var this_=this
		    hunyin.forEach(function(value,i){
		     	if(value.value==this_.response.hyzk){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedaboxx:function(){
	    		var zhi=''
		    	var this_=this
		    ABOxuexing.forEach(function(value,i){
		     	if(value.value==this_.response.aboxx){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedrhxx:function(){
	    		var zhi=''
		    	var this_=this
		    RHxuexing.forEach(function(value,i){
		     	if(value.value==this_.response.rhxx){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedguanxi:function(){
	    		var zhi=''
		    	var this_=this
		    guanxi.forEach(function(value,i){
		     	if(value.value==this_.response.lxrGx){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	   reversedwenhuacd:function(){
	    		var zhi=''
		    	var this_=this
		    wenhua.forEach(function(value,i){
		     	if(value.value==this_.response.whcd){
		     		return zhi=value.text;
		     	}
			})
	    		return zhi;
	   },
	},
	methods:{
		xiugai:function(){
			if(!this.response.xm||!this.response.zjhm||!this.response.lxr||!this.response.whcd||!this.response.lxrLxdh||!this.response.mobilePhone){
				log_message('请填写完整信息！')
				return false;
			}
			var reg2 = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;//身份证
			if(reg2.test(this.response.zjhm) == false) { 
				mui.toast("身份证输入不合法"); 
				return false; 
			}
			this.response.nl=(new Date()).getFullYear()-this.response.zjhm.substr(6, 4)
			if((new Date()).getMonth()<this.response.zjhm.substr(10, 2)){
				this.response.nl-=1;
			}
			this.response.csrq=this.response.zjhm.substr(6, 4)+"-"+this.response.zjhm.substr(10, 2)+"-"+this.response.zjhm.substr(12, 2)
			this.response.xb=this.response.zjhm.substr(16, 1)%2
			ajaxPostJson(
				Url.ASSESS_ADDINFO,
				this.response,
				function(data){
					console.log(data)
					if(data.status=='1'){
						log_message('新增成功！')
					}else{
						log_message(data.message||'新增失败！')
					}
				}
			)
		}
	}
});
(function($, doc) {
	$.init();
	$.ready(function() {
		/**
		 * 获取对象属性的值
		 * 主要用于过滤三级联动中，可能出现的最低级的数据不存在的情况，实际开发中需要注意这一点；
		 * @param {Object} obj 对象
		 * @param {String} param 属性名
		 */
		var _getParam = function(obj, param) {
			return obj[param] || '';
		};
		//民族
		var userPicker = new $.PopPicker();
		userPicker.setData(minzu);
		var showUserPickerButton = doc.getElementById('showUserPicker');
		showUserPickerButton.addEventListener('tap', function(event) {
			userPicker.show(function(items) {
				main.response.mz=items[0].value;
			});
		}, false);
		//国家
		var userPicker2 = new $.PopPicker();
		userPicker2.setData(guojia);
		var showUserPickerButton2 = doc.getElementById('showUserPicker2');
		showUserPickerButton2.addEventListener('tap', function(event) {
			userPicker2.show(function(items) {
				main.response.gj=items[0].value;
			});
		}, false);
		//婚姻
		var userPicker3 = new $.PopPicker();
		userPicker3.setData(hunyin);
		var showUserPickerButton3 = doc.getElementById('hunyinzk');
		showUserPickerButton3.addEventListener('tap', function(event) {
			userPicker3.show(function(items) {
				main.response.hyzk=items[0].value;
			});
		}, false);
		//abo血型
		var userPicker4 = new $.PopPicker();
		userPicker4.setData(ABOxuexing);
		var showUserPickerButton4 = doc.getElementById('aboxuexing');
		showUserPickerButton4.addEventListener('tap', function(event) {
			userPicker4.show(function(items) {
				main.response.aboxx=items[0].value;
			});
		}, false);
		//RH血型
		var userPicker5 = new $.PopPicker();
		userPicker5.setData(RHxuexing);
		var showUserPickerButton5 = doc.getElementById('rhxuexing');
		showUserPickerButton5.addEventListener('tap', function(event) {
			userPicker5.show(function(items) {
				main.response.rhxx=items[0].value;
			});
		}, false);
		//关系
		var userPicker6 = new $.PopPicker();
		userPicker6.setData(guanxi);
		var showUserPickerButton6 = doc.getElementById('lxrgx');
		showUserPickerButton6.addEventListener('tap', function(event) {
			userPicker6.show(function(items) {
				main.response.lxrGx=items[0].value;
			});
		}, false);
		//文化程度
		var userPicker7 = new $.PopPicker();
		userPicker7.setData(wenhua);
		var showUserPickerButton7 = doc.getElementById('wenhuacd');
		showUserPickerButton7.addEventListener('tap', function(event) {
			userPicker7.show(function(items) {
				main.response.whcd=items[0].value;
			});
		}, false);
	});
})(mui, document);